package com.mifengs.mall.ui.my;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.mifengs.mall.R;
import com.mifengs.commonbase.base.BaseActivity;
import com.mifengs.mall.entity.RedPacket;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RedPacketDetailActivity extends BaseActivity {

    @BindView(R.id.tv_amount)
    TextView mTvAmount;
    @BindView(R.id.tv_status)
    TextView mTvStatus;
    @BindView(R.id.tv_need_time)
    TextView mTvNeedTime;
    @BindView(R.id.tv_red_type)
    TextView mTvRedType;
    @BindView(R.id.tv_desc)
    TextView mTvDesc;
    @BindView(R.id.tv_from)
    TextView mTvFrom;
    @BindView(R.id.tv_fafang_time)
    TextView mTvFafangTime;

    private RedPacket redPacket;
    private String mNeedTime;
    private String mReStatus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_red_packet_detail);
        ButterKnife.bind(this);
        setStatusColorAndMode(R.color.white, true);
        initNavigationBar(true, "红包详情");
        redPacket = (RedPacket) getIntent().getSerializableExtra("redPacket");
        mNeedTime = getIntent().getStringExtra("needTime");
        mReStatus = getIntent().getStringExtra("reStatus");
        init();
    }

    private void init() {
//        String detail = "详情:    " +
//                "推荐会员130*******2334购买订单180890890金额99999.00元推荐会员130*******2334购买订单180890890金额99999.00元";
//        SpannableString spannableString = new SpannableString(detail);
//        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#EF2A34")),0,4, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
//        mTvDetail.setText(spannableString);

        if (redPacket != null) {

            mTvRedType.setText(redPacket.getRedEnvelopTypeText());

            mTvAmount.setText(redPacket.getCommissionAmount() + "元");


            try {
                String[] times = mNeedTime.split(",");
                if(times[1].equals("发放时间")){
//                    long time = redPacket.getDeadLine();
//                    Date date = new Date(time);
//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    String sTime = dateFormat.format(date);
//                    mTvNeedTime.setText("过期时间" + ":" + sTime);
                    mTvNeedTime.setVisibility(View.GONE);
                }else{
                    long time = Long.decode(times[0]);
                    Date date = new Date(time);
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String sTime = dateFormat.format(date);
                    mTvNeedTime.setText(times[1] + ":" + sTime);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }


            try {
                long time = redPacket.getCreateDate();
                Date date = new Date(time);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String sTime = dateFormat.format(date);
                mTvFafangTime.setText("发放时间" + ":" + sTime);

            } catch (Exception e) {
                e.printStackTrace();
            }


            mTvStatus.setText("状         态: " + mReStatus);


            mTvFrom.setText("来         源: " + redPacket.getCommissionTypeText());

//            String st = "";
//
//            switch (redPacket.getReceiveStatus()) {
//                case 0:
//                    st = "未领取";
//                    break;
//                case 1:
//                    st = "已领取";
//                    break;
//                case -1:
//                    st = "待结算";
//                    break;
//                case 2:
//                    st = "失效";
//                    break;
//            }
//
//
//            String status = "状态:    " + st;
//            SpannableString statusString = new SpannableString(status);
//            statusString.setSpan(new ForegroundColorSpan(Color.parseColor("#333333")), 0, 3, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
//            mTvStatus.setText(statusString);

            if (!TextUtils.isEmpty(redPacket.getSettlementDesc())) {
                mTvDesc.setVisibility(View.VISIBLE);
                mTvDesc.setText("温馨提示: " + redPacket.getSettlementDesc());
            }

//            if(redPacket.getReceiveStatus()==2){
//                mTvDesc.setText("温馨提示: "+redPacket.getSettlementDesc());
//            }


//            if (redPacket.getReceiveStatus() == 1) {
//                setRevTime();
//            }
//
//            setOverdueTime();

        }

    }

/*
    private void setOverdueTime() {
        long overdue = redPacket.getDeadLine();
        Date date = new Date(overdue);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String overdueTime = format.format(date);
        String overdueTimeComplete = "过期时间:    " + overdueTime;
        SpannableString overdueTimeString = new SpannableString(overdueTimeComplete);
        overdueTimeString.setSpan(new ForegroundColorSpan(Color.parseColor("#333333")), 0, 5, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        mTvOverdue.setText(overdueTimeString);
    }
*/

/*    private void setRevTime() {
        long revtm = redPacket.getModifyDate();
        Date date = new Date(revtm);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String revTime = format.format(date);
        String revTimeComplete = "领取时间:    " + revTime;
        SpannableString revTimeString = new SpannableString(revTimeComplete);
        revTimeString.setSpan(new ForegroundColorSpan(Color.parseColor("#333333")), 0, 5, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        mTvRevTime.setText(revTimeString);
        mTvRevTime.setVisibility(View.VISIBLE);
    }*/


}
